//index.js
const App =  getApp();
import { HomeModel } from '../../../models/home.js'
const ModelHome = new HomeModel()
Page({
  data: {
    statusBarHeight: App.globalData.statusBarHeight,
    isTabbar:false,
    gbCode: '',
    goodsInfo: {},
    userInfo: {},
    empty: false,
    userType: null
  },
  // 查询商品信息
  getGood() {
    const params = {
      gbCode: this.data.gbCode
    }
    ModelHome.queryByGbCode(params).then(res => {
      this.setData({
        goodsInfo: res.data.goodsInfo,
        userType: res.data.userType,
        empty: false
      })
    }).catch(err => {
      this.setData({
        empty: true
      })
    })
  },
  onLoad: function(options) {
    if(options.gbCode) {
      this.setData({
        gbCode: options.gbCode
      })
      this.getGood()
    }
    this.setData({
      userInfo: App.globalData.userInfo
    })
    // Do some initialize when page load.
  },
  onReady: function() {
    // Do something when page ready.
  },
  onShow: function() {
    // Do something when page show.
  },
  onHide: function() {
    // Do something when page hide.
  },
  onUnload: function() {
    // Do something when page close.
  },
  onPullDownRefresh: function() {
    // Do something when pull down.
  },
  onReachBottom: function() {
    // Do something when page reach bottom.
  },
  onShareAppMessage: function () {
    // return custom share data when user share.
  },
  onPageScroll: function() {
    // Do something when page scroll
  },
})